package cn.lqz.bucttrain.mapper;

import cn.lqz.bucttrain.annotations.AutoFill;
import cn.lqz.bucttrain.enums.OperationTypeEnum;
import cn.lqz.bucttrain.pojo.dto.RoutePageQueryDTO;
import cn.lqz.bucttrain.pojo.entity.Route;
import cn.lqz.bucttrain.pojo.vo.RouteVO;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface RouteMapper {
    /**
     * 根据routeId查询
     * @param routeId
     * @return
     */
    @Select("select * from route where route_id=#{routeId}")
    Route findByRouteId(Long routeId);

    /**
     * 加载或查询
     * @param routePageQueryDTO
     * @return
     */
    Page<RouteVO> findBatch(RoutePageQueryDTO routePageQueryDTO);

    /**
     * 查询是否存在列车使用时间冲突的路线
     * @param trainId
     * @param startStationStartTime
     * @param endStationEndTime
     * @return
     */
    List<Route> findClashByTrainIdAndStartStationStartTimeAndEndStationEndTime(Long trainId,LocalDateTime startStationStartTime,LocalDateTime endStationEndTime);
    /**
     * 查询是否存在列车使用时间冲突的路线
     * @param trainId
     * @param startStationStartTime
     * @param endStationEndTime
     * @return
     */
    List<Route> findClashByTrainIdAndStartStationStartTimeAndEndStationEndTimeAndRouteId(Long trainId,LocalDateTime startStationStartTime,LocalDateTime endStationEndTime,Long routeId);

    /**
     * 查询站点是否正在被路线使用
     * @param stationId
     * @param time
     * @return
     */
    List<Route> findExistByStationIdAndTime(Long stationId, LocalDateTime time);

    /**
     * 删除
     * @param routeId
     */
    @Delete("delete from route where route_id=#{routeId}")
    void deleteByRouteId(Long routeId);

    /**
     * 插入
     * @param route
     */
    @AutoFill(OperationTypeEnum.INSERT)
    void insert(Route route);

    /**
     * 修改
     * @param route
     */
    @AutoFill(OperationTypeEnum.UPDATE)
    void update(Route route);

}
